<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
	<head>
		<title>regist</title>
		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
		<link rel="stylesheet" type="text/css" href="css/style.css" />
		<link rel="stylesheet" type="text/css" href="css/sweetalert.css" />
	</head>
	<body>
		<div id="wrap">
			<div id="top_content">
					<div id="header">
						<div id="rightheader">
							<p>
								2009/11/20
								<br />
							</p>
						</div>
						<div id="topheader">
							<h1 id="title">
								<a href="#">main</a>
							</h1>
						</div>
						<div id="navigation">
						</div>
					</div>
				<div id="content">
					<p id="whereami">
					</p>
					<h1>
						注册
					</h1>
					<form>
						<table cellpadding="0" cellspacing="0" border="0"
							class="form_table">
							<tr>
								<td valign="middle" align="right">
									用户名:
								</td>
								<td valign="middle" align="left">
									<input type="text" class="inputgri" v-model="user.username" />
								</td>
							</tr>
							<tr>
								<td valign="middle" align="right">
									真实姓名:
								</td>
								<td valign="middle" align="left">
									<input type="text" class="inputgri" v-model="user.realname" />
								</td>
							</tr>
							<tr>
								<td valign="middle" align="right">
									密码:
								</td>
								<td valign="middle" align="left">
									<input type="password" class="inputgri" v-model="user.password" />
								</td>
							</tr>
							<tr>
								<td valign="middle" align="right">
									性别:
								</td>
								<td valign="middle" align="left">
									男
									<input type="radio" class="inputgri" v-model="user.sex" value="男" checked="checked"/>
									女
									<input type="radio" class="inputgri" v-model="user.sex" value="女"/>
								</td>
							</tr>
							
							<tr>
								<td valign="middle" align="right">
									验证码:
								</td>
								<td valign="middle" align="left">
									<input type="text" class="inputgri" v-model="code" />
								</td>
								<td>
								<img id="num" :src="url" />
								<a href="javascript:;" @click="getImg">换一张</a>
								</td>
							</tr>
						</table>
						<p>
							<input type="button" class="button" @click="register" value="Submit &raquo;" />
						</p>
					</form>
				</div>
			</div>
			<div id="footer">
				<div id="footer_bg">
				ABC@126.com
				</div>
			</div>
		</div>
	</body>
</html>
<!--引入Vue-->
<script src="/js/vue.js"></script>
<!--引入axios-->
<script src="/js/axios.min.js"></script>
<script src="/js/sweetalert.min.js"></script>

<script>
	var vue=new Vue({
		el:"#wrap",
		data:{
         url:"",
			code:"",
			user:{
         	    username:"",
				password:"",
                realname:"",
				sex:""
			}
		},
		created() {
			this.getUrlCommon()
		},
    methods: {
		//更换验证码
		getImg() {
			this.getUrlCommon()
		},
		//封装获取验证码方法
		getUrlCommon() {
			axios.get("http://localhost:8888/user/getImage?time=" + Math.random())
					.then(response => {
						this.url = response.data
					})
		},
		register(){
			axios.post("http://localhost:8888/user/register?code="+this.code,this.user)
					.then(response=>{

						if(response.data.state)
							swal({
								title: '提示',
								text: '你已经注册成功！',
								type: 'success',

							})


					})

	},

	}
	})

</script>